
select	a11.EmployeePayStatus  EmployeePayStatus,
	a13.DataItemSecondary  DataItemSecondary,
	max(DATEPART(MONTH, a13.DataItemSecondary))  CustCol_6,
	max(DATEPART(YEAR, a13.DataItemSecondary))  CustCol_7,
	a13.DateTerminated  DateTerminated,
	max(DATEPART(MONTH, a13.DateTerminated))  CustCol_8,
	max(DATEPART(YEAR, a13.DateTerminated))  CustCol_9,
	a11.EmployeeID  EmployeeNumberID,
	max(a14.EmployeeNumber)  EmployeeNumber,
	max(a14.EmployeeName)  EmployeeName,
	a12.Category20Code  Category20Code,
	max(a12.Category20)  Category20,
	a12.Category18Code  Category18Code,
	max(a12.Category18)  Category18,
	a12.CompanyNumber  CompanyNumber,
	count(distinct a11.EmployeeID)  WJXBFS1
from	HR_Star_Facts	a11
	join	Common_Star_BusinessUnit	a12
	  on 	(a11.BusinessUnitID = a12.BusinessUnitID)
	join	Payroll_Star_Employee	a13
	  on 	(a11.EmployeeID = a13.EmployeeID)
	join	Common_Star_Employee	a14
	  on 	(a11.EmployeeID = a14.EmployeeNumberID)
where	(((a11.EmployeeID)
 in	(select	r12.EmployeeNumberID
	from	HR_Star_Facts	r11
		cross join	Common_Star_Employee	r12
	where	(DATEPART(YEAR, r11.asofdate) > 2012
	 or (DATEPART(YEAR, r11.asofdate) = 2012
	 and DATEPART(MONTH, r11.asofdate) >=  1))))
 and (DATEPART(YEAR, a13.DataItemSecondary) < 2012
 or (DATEPART(YEAR, a13.DataItemSecondary) = 2012
 and DATEPART(MONTH, a13.DataItemSecondary) <=  1))
 and (DATEPART(YEAR, a13.DateTerminated) > 2012
 or (DATEPART(MONTH, a13.DateTerminated) > 1
 and DATEPART(YEAR, a13.DateTerminated) = 2012)
 or a13.DateTerminated = '1/1/1901')
 and (DATEPART(YEAR, a11.asofdate) > 2012
 or (DATEPART(YEAR, a11.asofdate) = 2012
 and DATEPART(MONTH, a11.asofdate) >=  1)))
group by	a11.EmployeePayStatus,
	a13.DataItemSecondary,
	a13.DateTerminated,
	a11.EmployeeID,
	a12.Category20Code,
	a12.Category18Code,
	a12.CompanyNumber


select	a11.EmployeePayStatus  EmployeePayStatus,
	a13.DataItemSecondary  DataItemSecondary,
	max(DATEPART(MONTH, a13.DataItemSecondary))  CustCol_6,
	max(DATEPART(YEAR, a13.DataItemSecondary))  CustCol_7,
	a13.DateTerminated  DateTerminated,
	max(DATEPART(MONTH, a13.DateTerminated))  CustCol_8,
	max(DATEPART(YEAR, a13.DateTerminated))  CustCol_9,
	a11.EmployeeID  EmployeeNumberID,
	max(a14.EmployeeNumber)  EmployeeNumber,
	max(a14.EmployeeName)  EmployeeName,
	a12.Category20Code  Category20Code,
	max(a12.Category20)  Category20,
	a12.Category18Code  Category18Code,
	max(a12.Category18)  Category18,
	a12.CompanyNumber  CompanyNumber,
	count(distinct a11.EmployeeID)  WJXBFS1
from	HR_Star_Facts	a11
	join	Common_Star_BusinessUnit	a12
	  on 	(a11.BusinessUnitID = a12.BusinessUnitID)
	join	Payroll_Star_Employee	a13
	  on 	(a11.EmployeeID = a13.EmployeeID)
	join	Common_Star_Employee	a14
	  on 	(a11.EmployeeID = a14.EmployeeNumberID)
where	(((a11.EmployeeID)
 in	(select	r12.EmployeeNumberID
	from	HR_Star_Facts	r11
		cross join	Common_Star_Employee	r12
	where	(DATEPART(YEAR, r11.asofdate) > 2012
	 or (DATEPART(YEAR, r11.asofdate) = 2012
	 and DATEPART(MONTH, r11.asofdate) >=  2))))
 and (DATEPART(YEAR, a13.DataItemSecondary) < 2012
 or (DATEPART(YEAR, a13.DataItemSecondary) = 2012
 and DATEPART(MONTH, a13.DataItemSecondary) <=  2))
 and (DATEPART(YEAR, a13.DateTerminated) > 2012
 or (DATEPART(MONTH, a13.DateTerminated) > 2
 and DATEPART(YEAR, a13.DateTerminated) = 2012)
 or a13.DateTerminated = '1/1/1901')
 and (DATEPART(YEAR, a11.asofdate) > 2012
 or (DATEPART(YEAR, a11.asofdate) = 2012
 and DATEPART(MONTH, a11.asofdate) >=  2)))
group by	a11.EmployeePayStatus,
	a13.DataItemSecondary,
	a13.DateTerminated,
	a11.EmployeeID,
	a12.Category20Code,
	a12.Category18Code,
	a12.CompanyNumber


select	a11.EmployeePayStatus  EmployeePayStatus,
	a13.DataItemSecondary  DataItemSecondary,
	max(DATEPART(MONTH, a13.DataItemSecondary))  CustCol_6,
	max(DATEPART(YEAR, a13.DataItemSecondary))  CustCol_7,
	a13.DateTerminated  DateTerminated,
	max(DATEPART(MONTH, a13.DateTerminated))  CustCol_8,
	max(DATEPART(YEAR, a13.DateTerminated))  CustCol_9,
	a11.EmployeeID  EmployeeNumberID,
	max(a14.EmployeeNumber)  EmployeeNumber,
	max(a14.EmployeeName)  EmployeeName,
	a12.Category20Code  Category20Code,
	max(a12.Category20)  Category20,
	a12.Category18Code  Category18Code,
	max(a12.Category18)  Category18,
	a12.CompanyNumber  CompanyNumber,
	count(distinct a11.EmployeeID)  WJXBFS1
from	HR_Star_Facts	a11
	join	Common_Star_BusinessUnit	a12
	  on 	(a11.BusinessUnitID = a12.BusinessUnitID)
	join	Payroll_Star_Employee	a13
	  on 	(a11.EmployeeID = a13.EmployeeID)
	join	Common_Star_Employee	a14
	  on 	(a11.EmployeeID = a14.EmployeeNumberID)
where	(((a11.EmployeeID)
 in	(select	r12.EmployeeNumberID
	from	HR_Star_Facts	r11
		cross join	Common_Star_Employee	r12
	where	(DATEPART(YEAR, r11.asofdate) > 2012
	 or (DATEPART(YEAR, r11.asofdate) = 2012
	 and DATEPART(MONTH, r11.asofdate) >=  3))))
 and (DATEPART(YEAR, a13.DataItemSecondary) < 2012
 or (DATEPART(YEAR, a13.DataItemSecondary) = 2012
 and DATEPART(MONTH, a13.DataItemSecondary) <=  3))
 and (DATEPART(YEAR, a13.DateTerminated) > 2012
 or (DATEPART(MONTH, a13.DateTerminated) > 3
 and DATEPART(YEAR, a13.DateTerminated) = 2012)
 or a13.DateTerminated = '1/1/1901')
 and (DATEPART(YEAR, a11.asofdate) > 2012
 or (DATEPART(YEAR, a11.asofdate) = 2012
 and DATEPART(MONTH, a11.asofdate) >=  3)))
group by	a11.EmployeePayStatus,
	a13.DataItemSecondary,
	a13.DateTerminated,
	a11.EmployeeID,
	a12.Category20Code,
	a12.Category18Code,
	a12.CompanyNumber


select	a11.EmployeePayStatus  EmployeePayStatus,
	a13.DataItemSecondary  DataItemSecondary,
	max(DATEPART(MONTH, a13.DataItemSecondary))  CustCol_6,
	max(DATEPART(YEAR, a13.DataItemSecondary))  CustCol_7,
	a13.DateTerminated  DateTerminated,
	max(DATEPART(MONTH, a13.DateTerminated))  CustCol_8,
	max(DATEPART(YEAR, a13.DateTerminated))  CustCol_9,
	a11.EmployeeID  EmployeeNumberID,
	max(a14.EmployeeNumber)  EmployeeNumber,
	max(a14.EmployeeName)  EmployeeName,
	a12.Category20Code  Category20Code,
	max(a12.Category20)  Category20,
	a12.Category18Code  Category18Code,
	max(a12.Category18)  Category18,
	a12.CompanyNumber  CompanyNumber,
	count(distinct a11.EmployeeID)  WJXBFS1
from	HR_Star_Facts	a11
	join	Common_Star_BusinessUnit	a12
	  on 	(a11.BusinessUnitID = a12.BusinessUnitID)
	join	Payroll_Star_Employee	a13
	  on 	(a11.EmployeeID = a13.EmployeeID)
	join	Common_Star_Employee	a14
	  on 	(a11.EmployeeID = a14.EmployeeNumberID)
where	(((a11.EmployeeID)
 in	(select	r12.EmployeeNumberID
	from	HR_Star_Facts	r11
		cross join	Common_Star_Employee	r12
	where	(DATEPART(YEAR, r11.asofdate) > 2012
	 or (DATEPART(YEAR, r11.asofdate) = 2012
	 and DATEPART(MONTH, r11.asofdate) >=  4))))
 and (DATEPART(YEAR, a13.DataItemSecondary) < 2012
 or (DATEPART(YEAR, a13.DataItemSecondary) = 2012
 and DATEPART(MONTH, a13.DataItemSecondary) <=  4))
 and (DATEPART(YEAR, a13.DateTerminated) > 2012
 or (DATEPART(MONTH, a13.DateTerminated) > 4
 and DATEPART(YEAR, a13.DateTerminated) = 2012)
 or a13.DateTerminated = '1/1/1901')
 and (DATEPART(YEAR, a11.asofdate) > 2012
 or (DATEPART(YEAR, a11.asofdate) = 2012
 and DATEPART(MONTH, a11.asofdate) >=  4)))
group by	a11.EmployeePayStatus,
	a13.DataItemSecondary,
	a13.DateTerminated,
	a11.EmployeeID,
	a12.Category20Code,
	a12.Category18Code,
	a12.CompanyNumber


select	a11.EmployeePayStatus  EmployeePayStatus,
	a13.DataItemSecondary  DataItemSecondary,
	max(DATEPART(MONTH, a13.DataItemSecondary))  CustCol_6,
	max(DATEPART(YEAR, a13.DataItemSecondary))  CustCol_7,
	a13.DateTerminated  DateTerminated,
	max(DATEPART(MONTH, a13.DateTerminated))  CustCol_8,
	max(DATEPART(YEAR, a13.DateTerminated))  CustCol_9,
	a11.EmployeeID  EmployeeNumberID,
	max(a14.EmployeeNumber)  EmployeeNumber,
	max(a14.EmployeeName)  EmployeeName,
	a12.Category20Code  Category20Code,
	max(a12.Category20)  Category20,
	a12.Category18Code  Category18Code,
	max(a12.Category18)  Category18,
	a12.CompanyNumber  CompanyNumber,
	count(distinct a11.EmployeeID)  WJXBFS1
from	HR_Star_Facts	a11
	join	Common_Star_BusinessUnit	a12
	  on 	(a11.BusinessUnitID = a12.BusinessUnitID)
	join	Payroll_Star_Employee	a13
	  on 	(a11.EmployeeID = a13.EmployeeID)
	join	Common_Star_Employee	a14
	  on 	(a11.EmployeeID = a14.EmployeeNumberID)
where	(((a11.EmployeeID)
 in	(select	r12.EmployeeNumberID
	from	HR_Star_Facts	r11
		cross join	Common_Star_Employee	r12
	where	(DATEPART(YEAR, r11.asofdate) > 2012
	 or (DATEPART(YEAR, r11.asofdate) = 2012
	 and DATEPART(MONTH, r11.asofdate) >=  5))))
 and (DATEPART(YEAR, a13.DataItemSecondary) < 2012
 or (DATEPART(YEAR, a13.DataItemSecondary) = 2012
 and DATEPART(MONTH, a13.DataItemSecondary) <=  5))
 and (DATEPART(YEAR, a13.DateTerminated) > 2012
 or (DATEPART(MONTH, a13.DateTerminated) > 5
 and DATEPART(YEAR, a13.DateTerminated) = 2012)
 or a13.DateTerminated = '1/1/1901')
 and (DATEPART(YEAR, a11.asofdate) > 2012
 or (DATEPART(YEAR, a11.asofdate) = 2012
 and DATEPART(MONTH, a11.asofdate) >=  5)))
group by	a11.EmployeePayStatus,
	a13.DataItemSecondary,
	a13.DateTerminated,
	a11.EmployeeID,
	a12.Category20Code,
	a12.Category18Code,
	a12.CompanyNumber


select	a11.EmployeePayStatus  EmployeePayStatus,
	a13.DataItemSecondary  DataItemSecondary,
	max(DATEPART(MONTH, a13.DataItemSecondary))  CustCol_6,
	max(DATEPART(YEAR, a13.DataItemSecondary))  CustCol_7,
	a13.DateTerminated  DateTerminated,
	max(DATEPART(MONTH, a13.DateTerminated))  CustCol_8,
	max(DATEPART(YEAR, a13.DateTerminated))  CustCol_9,
	a11.EmployeeID  EmployeeNumberID,
	max(a14.EmployeeNumber)  EmployeeNumber,
	max(a14.EmployeeName)  EmployeeName,
	a12.Category20Code  Category20Code,
	max(a12.Category20)  Category20,
	a12.Category18Code  Category18Code,
	max(a12.Category18)  Category18,
	a12.CompanyNumber  CompanyNumber,
	count(distinct a11.EmployeeID)  WJXBFS1
from	HR_Star_Facts	a11
	join	Common_Star_BusinessUnit	a12
	  on 	(a11.BusinessUnitID = a12.BusinessUnitID)
	join	Payroll_Star_Employee	a13
	  on 	(a11.EmployeeID = a13.EmployeeID)
	join	Common_Star_Employee	a14
	  on 	(a11.EmployeeID = a14.EmployeeNumberID)
where	(((a11.EmployeeID)
 in	(select	r12.EmployeeNumberID
	from	HR_Star_Facts	r11
		cross join	Common_Star_Employee	r12
	where	(DATEPART(YEAR, r11.asofdate) > 2012
	 or (DATEPART(YEAR, r11.asofdate) = 2012
	 and DATEPART(MONTH, r11.asofdate) >=  6))))
 and (DATEPART(YEAR, a13.DataItemSecondary) < 2012
 or (DATEPART(YEAR, a13.DataItemSecondary) = 2012
 and DATEPART(MONTH, a13.DataItemSecondary) <=  6))
 and (DATEPART(YEAR, a13.DateTerminated) > 2012
 or (DATEPART(MONTH, a13.DateTerminated) > 6
 and DATEPART(YEAR, a13.DateTerminated) = 2012)
 or a13.DateTerminated = '1/1/1901')
 and (DATEPART(YEAR, a11.asofdate) > 2012
 or (DATEPART(YEAR, a11.asofdate) = 2012
 and DATEPART(MONTH, a11.asofdate) >=  6)))
group by	a11.EmployeePayStatus,
	a13.DataItemSecondary,
	a13.DateTerminated,
	a11.EmployeeID,
	a12.Category20Code,
	a12.Category18Code,
	a12.CompanyNumber


select	a11.EmployeePayStatus  EmployeePayStatus,
	a13.DataItemSecondary  DataItemSecondary,
	max(DATEPART(MONTH, a13.DataItemSecondary))  CustCol_6,
	max(DATEPART(YEAR, a13.DataItemSecondary))  CustCol_7,
	a13.DateTerminated  DateTerminated,
	max(DATEPART(MONTH, a13.DateTerminated))  CustCol_8,
	max(DATEPART(YEAR, a13.DateTerminated))  CustCol_9,
	a11.EmployeeID  EmployeeNumberID,
	max(a14.EmployeeNumber)  EmployeeNumber,
	max(a14.EmployeeName)  EmployeeName,
	a12.Category20Code  Category20Code,
	max(a12.Category20)  Category20,
	a12.Category18Code  Category18Code,
	max(a12.Category18)  Category18,
	a12.CompanyNumber  CompanyNumber,
	count(distinct a11.EmployeeID)  WJXBFS1
from	HR_Star_Facts	a11
	join	Common_Star_BusinessUnit	a12
	  on 	(a11.BusinessUnitID = a12.BusinessUnitID)
	join	Payroll_Star_Employee	a13
	  on 	(a11.EmployeeID = a13.EmployeeID)
	join	Common_Star_Employee	a14
	  on 	(a11.EmployeeID = a14.EmployeeNumberID)
where	(((a11.EmployeeID)
 in	(select	r12.EmployeeNumberID
	from	HR_Star_Facts	r11
		cross join	Common_Star_Employee	r12
	where	(DATEPART(YEAR, r11.asofdate) > 2012
	 or (DATEPART(YEAR, r11.asofdate) = 2012
	 and DATEPART(MONTH, r11.asofdate) >=  7))))
 and (DATEPART(YEAR, a13.DataItemSecondary) < 2012
 or (DATEPART(YEAR, a13.DataItemSecondary) = 2012
 and DATEPART(MONTH, a13.DataItemSecondary) <=  7))
 and (DATEPART(YEAR, a13.DateTerminated) > 2012
 or (DATEPART(MONTH, a13.DateTerminated) > 7
 and DATEPART(YEAR, a13.DateTerminated) = 2012)
 or a13.DateTerminated = '1/1/1901')
 and (DATEPART(YEAR, a11.asofdate) > 2012
 or (DATEPART(YEAR, a11.asofdate) = 2012
 and DATEPART(MONTH, a11.asofdate) >=  7)))
group by	a11.EmployeePayStatus,
	a13.DataItemSecondary,
	a13.DateTerminated,
	a11.EmployeeID,
	a12.Category20Code,
	a12.Category18Code,
	a12.CompanyNumber


select	a11.EmployeePayStatus  EmployeePayStatus,
	a13.DataItemSecondary  DataItemSecondary,
	max(DATEPART(MONTH, a13.DataItemSecondary))  CustCol_6,
	max(DATEPART(YEAR, a13.DataItemSecondary))  CustCol_7,
	a13.DateTerminated  DateTerminated,
	max(DATEPART(MONTH, a13.DateTerminated))  CustCol_8,
	max(DATEPART(YEAR, a13.DateTerminated))  CustCol_9,
	a11.EmployeeID  EmployeeNumberID,
	max(a14.EmployeeNumber)  EmployeeNumber,
	max(a14.EmployeeName)  EmployeeName,
	a12.Category20Code  Category20Code,
	max(a12.Category20)  Category20,
	a12.Category18Code  Category18Code,
	max(a12.Category18)  Category18,
	a12.CompanyNumber  CompanyNumber,
	count(distinct a11.EmployeeID)  WJXBFS1
from	HR_Star_Facts	a11
	join	Common_Star_BusinessUnit	a12
	  on 	(a11.BusinessUnitID = a12.BusinessUnitID)
	join	Payroll_Star_Employee	a13
	  on 	(a11.EmployeeID = a13.EmployeeID)
	join	Common_Star_Employee	a14
	  on 	(a11.EmployeeID = a14.EmployeeNumberID)
where	(((a11.EmployeeID)
 in	(select	r12.EmployeeNumberID
	from	HR_Star_Facts	r11
		cross join	Common_Star_Employee	r12
	where	(DATEPART(YEAR, r11.asofdate) > 2012
	 or (DATEPART(YEAR, r11.asofdate) = 2012
	 and DATEPART(MONTH, r11.asofdate) >=  8))))
 and (DATEPART(YEAR, a13.DataItemSecondary) < 2012
 or (DATEPART(YEAR, a13.DataItemSecondary) = 2012
 and DATEPART(MONTH, a13.DataItemSecondary) <=  8))
 and (DATEPART(YEAR, a13.DateTerminated) > 2012
 or (DATEPART(MONTH, a13.DateTerminated) > 8
 and DATEPART(YEAR, a13.DateTerminated) = 2012)
 or a13.DateTerminated = '1/1/1901')
 and (DATEPART(YEAR, a11.asofdate) > 2012
 or (DATEPART(YEAR, a11.asofdate) = 2012
 and DATEPART(MONTH, a11.asofdate) >=  8)))
group by	a11.EmployeePayStatus,
	a13.DataItemSecondary,
	a13.DateTerminated,
	a11.EmployeeID,
	a12.Category20Code,
	a12.Category18Code,
	a12.CompanyNumber


select	a11.EmployeePayStatus  EmployeePayStatus,
	a13.DataItemSecondary  DataItemSecondary,
	max(DATEPART(MONTH, a13.DataItemSecondary))  CustCol_6,
	max(DATEPART(YEAR, a13.DataItemSecondary))  CustCol_7,
	a13.DateTerminated  DateTerminated,
	max(DATEPART(MONTH, a13.DateTerminated))  CustCol_8,
	max(DATEPART(YEAR, a13.DateTerminated))  CustCol_9,
	a11.EmployeeID  EmployeeNumberID,
	max(a14.EmployeeNumber)  EmployeeNumber,
	max(a14.EmployeeName)  EmployeeName,
	a12.Category20Code  Category20Code,
	max(a12.Category20)  Category20,
	a12.Category18Code  Category18Code,
	max(a12.Category18)  Category18,
	a12.CompanyNumber  CompanyNumber,
	count(distinct a11.EmployeeID)  WJXBFS1
from	HR_Star_Facts	a11
	join	Common_Star_BusinessUnit	a12
	  on 	(a11.BusinessUnitID = a12.BusinessUnitID)
	join	Payroll_Star_Employee	a13
	  on 	(a11.EmployeeID = a13.EmployeeID)
	join	Common_Star_Employee	a14
	  on 	(a11.EmployeeID = a14.EmployeeNumberID)
where	(((a11.EmployeeID)
 in	(select	r12.EmployeeNumberID
	from	HR_Star_Facts	r11
		cross join	Common_Star_Employee	r12
	where	(DATEPART(YEAR, r11.asofdate) > 2012
	 or (DATEPART(YEAR, r11.asofdate) = 2012
	 and DATEPART(MONTH, r11.asofdate) >=  9))))
 and (DATEPART(YEAR, a13.DataItemSecondary) < 2012
 or (DATEPART(YEAR, a13.DataItemSecondary) = 2012
 and DATEPART(MONTH, a13.DataItemSecondary) <=  9))
 and (DATEPART(YEAR, a13.DateTerminated) > 2012
 or (DATEPART(MONTH, a13.DateTerminated) > 9
 and DATEPART(YEAR, a13.DateTerminated) = 2012)
 or a13.DateTerminated = '1/1/1901')
 and (DATEPART(YEAR, a11.asofdate) > 2012
 or (DATEPART(YEAR, a11.asofdate) = 2012
 and DATEPART(MONTH, a11.asofdate) >=  9)))
group by	a11.EmployeePayStatus,
	a13.DataItemSecondary,
	a13.DateTerminated,
	a11.EmployeeID,
	a12.Category20Code,
	a12.Category18Code,
	a12.CompanyNumber


select	a11.EmployeePayStatus  EmployeePayStatus,
	a13.DataItemSecondary  DataItemSecondary,
	max(DATEPART(MONTH, a13.DataItemSecondary))  CustCol_6,
	max(DATEPART(YEAR, a13.DataItemSecondary))  CustCol_7,
	a13.DateTerminated  DateTerminated,
	max(DATEPART(MONTH, a13.DateTerminated))  CustCol_8,
	max(DATEPART(YEAR, a13.DateTerminated))  CustCol_9,
	a11.EmployeeID  EmployeeNumberID,
	max(a14.EmployeeNumber)  EmployeeNumber,
	max(a14.EmployeeName)  EmployeeName,
	a12.Category20Code  Category20Code,
	max(a12.Category20)  Category20,
	a12.Category18Code  Category18Code,
	max(a12.Category18)  Category18,
	a12.CompanyNumber  CompanyNumber,
	count(distinct a11.EmployeeID)  WJXBFS1
from	HR_Star_Facts	a11
	join	Common_Star_BusinessUnit	a12
	  on 	(a11.BusinessUnitID = a12.BusinessUnitID)
	join	Payroll_Star_Employee	a13
	  on 	(a11.EmployeeID = a13.EmployeeID)
	join	Common_Star_Employee	a14
	  on 	(a11.EmployeeID = a14.EmployeeNumberID)
where	(((a11.EmployeeID)
 in	(select	r12.EmployeeNumberID
	from	HR_Star_Facts	r11
		cross join	Common_Star_Employee	r12
	where	(DATEPART(YEAR, r11.asofdate) > 2012
	 or (DATEPART(YEAR, r11.asofdate) = 2012
	 and DATEPART(MONTH, r11.asofdate) >=  10))))
 and (DATEPART(YEAR, a13.DataItemSecondary) < 2012
 or (DATEPART(YEAR, a13.DataItemSecondary) = 2012
 and DATEPART(MONTH, a13.DataItemSecondary) <=  10))
 and (DATEPART(YEAR, a13.DateTerminated) > 2012
 or (DATEPART(MONTH, a13.DateTerminated) > 10
 and DATEPART(YEAR, a13.DateTerminated) = 2012)
 or a13.DateTerminated = '1/1/1901')
 and (DATEPART(YEAR, a11.asofdate) > 2012
 or (DATEPART(YEAR, a11.asofdate) = 2012
 and DATEPART(MONTH, a11.asofdate) >=  10)))
group by	a11.EmployeePayStatus,
	a13.DataItemSecondary,
	a13.DateTerminated,
	a11.EmployeeID,
	a12.Category20Code,
	a12.Category18Code,
	a12.CompanyNumber


select	a11.EmployeePayStatus  EmployeePayStatus,
	a13.DataItemSecondary  DataItemSecondary,
	max(DATEPART(MONTH, a13.DataItemSecondary))  CustCol_6,
	max(DATEPART(YEAR, a13.DataItemSecondary))  CustCol_7,
	a13.DateTerminated  DateTerminated,
	max(DATEPART(MONTH, a13.DateTerminated))  CustCol_8,
	max(DATEPART(YEAR, a13.DateTerminated))  CustCol_9,
	a11.EmployeeID  EmployeeNumberID,
	max(a14.EmployeeNumber)  EmployeeNumber,
	max(a14.EmployeeName)  EmployeeName,
	a12.Category20Code  Category20Code,
	max(a12.Category20)  Category20,
	a12.Category18Code  Category18Code,
	max(a12.Category18)  Category18,
	a12.CompanyNumber  CompanyNumber,
	count(distinct a11.EmployeeID)  WJXBFS1
from	HR_Star_Facts	a11
	join	Common_Star_BusinessUnit	a12
	  on 	(a11.BusinessUnitID = a12.BusinessUnitID)
	join	Payroll_Star_Employee	a13
	  on 	(a11.EmployeeID = a13.EmployeeID)
	join	Common_Star_Employee	a14
	  on 	(a11.EmployeeID = a14.EmployeeNumberID)
where	(((a11.EmployeeID)
 in	(select	r12.EmployeeNumberID
	from	HR_Star_Facts	r11
		cross join	Common_Star_Employee	r12
	where	(DATEPART(YEAR, r11.asofdate) > 2012
	 or (DATEPART(YEAR, r11.asofdate) = 2012
	 and DATEPART(MONTH, r11.asofdate) >=  11))))
 and (DATEPART(YEAR, a13.DataItemSecondary) < 2012
 or (DATEPART(YEAR, a13.DataItemSecondary) = 2012
 and DATEPART(MONTH, a13.DataItemSecondary) <=  11))
 and (DATEPART(YEAR, a13.DateTerminated) > 2012
 or (DATEPART(MONTH, a13.DateTerminated) > 11
 and DATEPART(YEAR, a13.DateTerminated) = 2012)
 or a13.DateTerminated = '1/1/1901')
 and (DATEPART(YEAR, a11.asofdate) > 2012
 or (DATEPART(YEAR, a11.asofdate) = 2012
 and DATEPART(MONTH, a11.asofdate) >=  11)))
group by	a11.EmployeePayStatus,
	a13.DataItemSecondary,
	a13.DateTerminated,
	a11.EmployeeID,
	a12.Category20Code,
	a12.Category18Code,
	a12.CompanyNumber


select	a11.EmployeePayStatus  EmployeePayStatus,
	a13.DataItemSecondary  DataItemSecondary,
	max(DATEPART(MONTH, a13.DataItemSecondary))  CustCol_6,
	max(DATEPART(YEAR, a13.DataItemSecondary))  CustCol_7,
	a13.DateTerminated  DateTerminated,
	max(DATEPART(MONTH, a13.DateTerminated))  CustCol_8,
	max(DATEPART(YEAR, a13.DateTerminated))  CustCol_9,
	a11.EmployeeID  EmployeeNumberID,
	max(a14.EmployeeNumber)  EmployeeNumber,
	max(a14.EmployeeName)  EmployeeName,
	a12.Category20Code  Category20Code,
	max(a12.Category20)  Category20,
	a12.Category18Code  Category18Code,
	max(a12.Category18)  Category18,
	a12.CompanyNumber  CompanyNumber,
	count(distinct a11.EmployeeID)  WJXBFS1
from	HR_Star_Facts	a11
	join	Common_Star_BusinessUnit	a12
	  on 	(a11.BusinessUnitID = a12.BusinessUnitID)
	join	Payroll_Star_Employee	a13
	  on 	(a11.EmployeeID = a13.EmployeeID)
	join	Common_Star_Employee	a14
	  on 	(a11.EmployeeID = a14.EmployeeNumberID)
where	(((a11.EmployeeID)
 in	(select	r12.EmployeeNumberID
	from	HR_Star_Facts	r11
		cross join	Common_Star_Employee	r12
	where	(DATEPART(YEAR, r11.asofdate) > 2012
	 or (DATEPART(YEAR, r11.asofdate) = 2012
	 and DATEPART(MONTH, r11.asofdate) >=  12))))
 and (DATEPART(YEAR, a13.DataItemSecondary) < 2012
 or (DATEPART(YEAR, a13.DataItemSecondary) = 2012
 and DATEPART(MONTH, a13.DataItemSecondary) <=  12))
 and (DATEPART(YEAR, a13.DateTerminated) > 2012
 or (DATEPART(MONTH, a13.DateTerminated) > 12
 and DATEPART(YEAR, a13.DateTerminated) = 2012)
 or a13.DateTerminated = '1/1/1901')
 and (DATEPART(YEAR, a11.asofdate) > 2012
 or (DATEPART(YEAR, a11.asofdate) = 2012
 and DATEPART(MONTH, a11.asofdate) >=  12)))
group by	a11.EmployeePayStatus,
	a13.DataItemSecondary,
	a13.DateTerminated,
	a11.EmployeeID,
	a12.Category20Code,
	a12.Category18Code,
	a12.CompanyNumber
